﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using ListenMusic.Playlist_ServiceReference;
namespace ListenMusic.Models.Reposistory.User
{
    public class PlaylistReposistory
    {
       
        
        public List<Playlist> getPlaylist_ByMemberID(string UserName)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                Playlist[] pl = playlistCLient.getPlaylistByMemberID(UserName);
                return pl.ToList();
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public bool AddMusic_Into_Playlist(Favorite f)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "clientuser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.InsertMusic_Into_Favorites(f);
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public List<FavoritePlayList> getSongInPlaylist(string Username)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                FavoritePlayList[] fl = playlistCLient.getSongInPlaylist_ByMemberID(Username);
                return fl.ToList();
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public bool AddNewPlaylist(Playlist pl)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.InsertPlaylist(pl);
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public List<FavoritePlayList> getSongInSpecificPlaylist(string Username, int PlaylistID)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                FavoritePlayList[] lstsong = playlistCLient.getSongInSpecificPlaylist(Username, PlaylistID);
                return lstsong.ToList();
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public bool EditPlaylist(Playlist pl)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.EditPlaylist(pl);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        public Playlist getPlayList_ByPlaylistID(int PlaylistID)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.getPlaylist_ByPlaylistID(PlaylistID);
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public bool changePlaylist_Picture(int plid,string imgurl)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.EditPlayListPicture(plid, imgurl);
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public bool removeSonginPlaylist(int fid)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.DeleteSongInPlaylist(fid);
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
        public bool removePlaylist(int plid)
        {
            try
            {
                PlaylistServiceClient playlistCLient = new PlaylistServiceClient();
                playlistCLient.ClientCredentials.UserName.UserName = "ClientUser";
                playlistCLient.ClientCredentials.UserName.Password = "123456";
                return playlistCLient.DeletePlaylist(plid);
            }
            catch (FaultException ex)
            {
                throw ex;
            }
        }
    }
}